﻿using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using FoodBank.Resources;

namespace FoodBank.Core.Models
{
    public class Product : AuditableEntity
    {
        [ScaffoldColumn(false)]
        public int ProductId { get; set; }

        [Display(ResourceType = typeof(ProductResources), Name = "Name")]
        [Required(ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "NameRequired")]
        [StringLength(50, ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "NameLong")]  
        public string Name { get; set; }

        [Display(ResourceType = typeof(ProductResources), Name = "ServingSize")]
        [DisplayFormat(DataFormatString = "{0:#,##0.000#}", ApplyFormatInEditMode = true)]
        [Required(ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "ServingSizeRequired")]
        [RegularExpression(@"[-+]?[0-9]*\.?[0-9]?[0-9]", ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "ServingSizeMustBeNumber")]
        [Range(0, 999, ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "ServingSizeRange")]
        public double ServingSize { get; set; }

        [Display(ResourceType = typeof(ProductResources), Name = "Calories")]
        [DisplayFormat(DataFormatString = "{0:#,##0.000#}", ApplyFormatInEditMode = true)]
        [Required(ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "CaloriesRequired")]
        [RegularExpression(@"[-+]?[0-9]*\.?[0-9]?[0-9]", ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "CaloriesMustBeNumber")]
        [Range(0, 999, ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "CaloriesRange")]
        public double Calories { get; set; }

        [Display(ResourceType = typeof(ProductResources), Name = "Proteins")]
        [DisplayFormat(DataFormatString = "{0:#,##0.000#}", ApplyFormatInEditMode = true)]
        [Required(ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "ProteinsRequired")]
        [RegularExpression(@"[-+]?[0-9]*\.?[0-9]?[0-9]", ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "ProteinsMustBeNumber")]
        [Range(0, 999, ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "ProteinsRange")]
        public double Proteins { get; set; }

        [Display(ResourceType = typeof(ProductResources), Name = "Carbohydrates")]
        [DisplayFormat(DataFormatString = "{0:#,##0.000#}", ApplyFormatInEditMode = true)]
        [Required(ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "CarbohydratesRequired")]
        [RegularExpression(@"[-+]?[0-9]*\.?[0-9]?[0-9]", ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "CarbohydratesMustBeNumber")]
        [Range(0, 999, ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "CarbohydratesRange")]
        public double Carbohydrates { get; set; }

        [Display(ResourceType = typeof(ProductResources), Name = "Sugar")]
        [DisplayFormat(DataFormatString = "{0:#,##0.000#}", ApplyFormatInEditMode = true)]
        [RegularExpression(@"[-+]?[0-9]*\.?[0-9]?[0-9]", ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "SugarMustBeNumber")]
        [Range(0, 999, ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "SugarRange")]
        public double? Sugar { get; set; }

        [Display(ResourceType = typeof(ProductResources), Name = "Fibres")]
        [DisplayFormat(DataFormatString = "{0:#,##0.000#}", ApplyFormatInEditMode = true)]
        [RegularExpression(@"[-+]?[0-9]*\.?[0-9]?[0-9]", ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "FibresMustBeNumber")]
        [Range(0, 999, ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "FibresRange")]
        public double? Fibres { get; set; }

        [Display(ResourceType = typeof(ProductResources), Name = "Fat")]
        [DisplayFormat(DataFormatString = "{0:#,##0.000#}", ApplyFormatInEditMode = true)]
        [Required(ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "FatRequired")]
        [RegularExpression(@"[-+]?[0-9]*\.?[0-9]?[0-9]", ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "FatMustBeNumber")]
        [Range(0, 999, ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "FatRange")]
        public double Fat { get; set; }

        [Display(ResourceType = typeof(ProductResources), Name = "SaturatedFat")]
        [DisplayFormat(DataFormatString = "{0:#,##0.000#}", ApplyFormatInEditMode = true)]
        [RegularExpression(@"[-+]?[0-9]*\.?[0-9]?[0-9]", ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "SaturatedFatMustBeNumber")]
        [Range(0, 999, ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "SaturatedFatRange")]
        public double? SaturatedFat { get; set; }

        [Display(ResourceType = typeof(ProductResources), Name = "Salt")]
        [DisplayFormat(DataFormatString = "{0:#,##0.000#}", ApplyFormatInEditMode = true)]
        [RegularExpression(@"[-+]?[0-9]*\.?[0-9]?[0-9]", ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "SaltMustBeNumber")]
        [Range(0, 999, ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "SaltRange")]
        public double? Salt { get; set; }

        [ScaffoldColumn(false)]
        [Display(ResourceType = typeof(ProductResources), Name = "Brand")]
        [Required(ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "BrandRequired")]
        public int BrandId { get; set; }

        public virtual Brand Brand { get; set; }

        [ScaffoldColumn(false)]
        [Display(ResourceType = typeof(ProductResources), Name = "Category")]
        [Required(ErrorMessageResourceType = typeof(ProductResources), ErrorMessageResourceName = "CategoryRequired")]
        public int ProductCategoryId { get; set; }

        public virtual ProductCategory ProductCategory { get; set; }

        [Timestamp, ScaffoldColumn(false)]
        public byte[] TimeStamp { get; set; }

        [NotMapped, ScaffoldColumn(false)]
        [Display(ResourceType = typeof(ProductResources), Name = "DailyRecommendedCaloriesPercentage")]
        public double DailyRecommendedCaloriesPercentage { get; set; }

        [NotMapped, ScaffoldColumn(false)]
        [Display(ResourceType = typeof(ProductResources), Name = "DailyRecommendedFatPercentage")]
        public double DailyRecommendedFatPercentage { get; set; }

        [NotMapped, ScaffoldColumn(false)]
        [Display(ResourceType = typeof(ProductResources), Name = "DailyRecommendedSaturatedFatPercentage")]
        public double DailyRecommendedSaturatedFatPercentage { get; set; }

        [NotMapped, ScaffoldColumn(false)]
        [Display(ResourceType = typeof(ProductResources), Name = "DailyRecommendedSodiumPercentage")]
        public double DailyRecommendedSodiumPercentage { get; set; }

        [NotMapped, ScaffoldColumn(false)]
        [Display(ResourceType = typeof(ProductResources), Name = "DailyRecommendedCarbohydratePercentage")]
        public double DailyRecommendedCarbohydratePercentage { get; set; }

        [NotMapped, ScaffoldColumn(false)]
        [Display(ResourceType = typeof(ProductResources), Name = "DailyRecommendedDietaryFiberPercentage")]
        public double DailyRecommendedDietaryFiberPercentage { get; set; }

        [NotMapped, ScaffoldColumn(false)]
        [Display(ResourceType = typeof(ProductResources), Name = "DailyRecommendedProteinPercentage")]
        public double DailyRecommendedProteinPercentage { get; set; }

        [NotMapped, ScaffoldColumn(false)]
        [Display(ResourceType = typeof(ProductResources), Name = "DailyRecommendedSugarPercentage")]
        public double DailyRecommendedSugarPercentage { get; set; }
    }
}